package idv.takeshi.software.productline.bookstore.domain.model.order;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * A abstract super invoice for every kind of invoices.
 * @author takeshi
 *
 */
@Entity
public class Invoice {
	
	@Id
    @GeneratedValue(strategy = GenerationType.TABLE)
	private Long id;
	
	@Column(length = 50, name = "INVOICE_TITLE")
	private String invoiceTitle;
	@Column(length = 10, name = "UNIFORM_NO") 
	private String uniformNumber;
	@Column(length = 10, name = "INVOICE_NO") 
	private String invoiceNumber;
	@Column(nullable = false, name = "UPDATE_TIME") 
	private Date updateTime;

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the invoiceTitle
	 */
	public String getInvoiceTitle() {
		return invoiceTitle;
	}

	/**
	 * @param invoiceTitle the invoiceTitle to set
	 */
	public void setInvoiceTitle(String invoiceTitle) {
		this.invoiceTitle = invoiceTitle;
	}

	/**
	 * @return the uniformNumber
	 */
	public String getUniformNumber() {
		return uniformNumber;
	}

	/**
	 * @param uniformNumber the uniformNumber to set
	 */
	public void setUniformNumber(String uniformNumber) {
		this.uniformNumber = uniformNumber;
	}

	/**
	 * @return the invoiceNumber
	 */
	public String getInvoiceNumber() {
		return invoiceNumber;
	}

	/**
	 * @param invoiceNumber the invoiceNumber to set
	 */
	public void setInvoiceNumber(String invoiceNumber) {
		this.invoiceNumber = invoiceNumber;
	}

	/**
	 * @return the updateTime
	 */
	public Date getUpdateTime() {
		return updateTime;
	}

	/**
	 * @param updateTime the updateTime to set
	 */
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj == null) { return false; }
		   if (obj == this) { return true; }
		   if (obj.getClass() != getClass()) {
		     return false;
		   }
		   Invoice rhs = (Invoice) obj;
		   return new EqualsBuilder()
			   .append(this.id, rhs.id)
			   .append(this.invoiceTitle, rhs.invoiceTitle)
			   .append(this.uniformNumber, rhs.uniformNumber)
			   .append(this.invoiceNumber, rhs.invoiceNumber)
			   .append(this.updateTime, rhs.updateTime)
		       .isEquals();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return new HashCodeBuilder(59, 97).
	       append(this.id).
	       append(this.invoiceTitle).
	       append(this.uniformNumber).
	       append(this.invoiceNumber).
	       append(this.updateTime).
	       toHashCode();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
	}
	 
}
 
